﻿
using ATMClientWinForm.ATMService;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ATMClientWinForm
{
    public partial class LoginForm : Form
    {
        ATMService.ATMServiceSoapClient Client;
        public LoginForm()
        {
            InitializeComponent();
            Client = new ATMService.ATMServiceSoapClient();
        }

        
        private void btnLogin_Click(object sender, EventArgs e)
        {
            
            Account acc = null;
            if (txtIp.Text.Trim() != "" || txtPin.Text.Trim() != ""||txtIp.Text.Length <= 10 ||txtPin.Text.Length <=10)
            {
                acc = Login(txtIp.Text);
                if(acc != null)
                {
                    if (acc.Pin == txtPin.Text.Trim())
                    {
                        //MessageBox.Show("Login Success..!");
                        ManageATM mn = new ManageATM(acc);
                        mn.Show();
                        this.Hide();
                    }
                    else
                    {
                        MessageBox.Show("Login False..!");
                    }
                }
                else
                {
                    MessageBox.Show("Login False..!");
                }
            }
            else {
                txtIp.Text = "";
                txtPin.Text = "";
                txtIp.Focus();
            }
        }

        Account Login(string Ip)
        {
             return Client.GetAccount(Ip);
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void txtPin_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar != '\b')
            {

                if (e.Handled = !char.IsNumber(e.KeyChar))
                {
                    MessageBox.Show("Must enter number");
                }

            }
        }
    }
}
